﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace project2
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                //输入运算对象和运算符
                Console.Write("请输入数字A：");
                string strNumberA = Console.ReadLine();
                Console.Write("请输入运算符（+，-，*，/, %）：");
                string strOperate = Console.ReadLine();
                Console.Write("请输入数字B：");
                string strNumberB = Console.ReadLine();

                //由工厂创建运算对象
                Operation operate = OperationFactory.CreateOperate(strOperate);

                //设置要运算的数据
                operate.NumberA = Convert.ToDouble(strNumberA);
                operate.NumberB = Convert.ToDouble(strNumberB);

                //具体作运算--动态决定调用哪个子类的GetResult（）方法
                double result = operate.GetResult();

                //显示运算结果
                Console.WriteLine(strNumberA + strOperate + strNumberB + " = " + result);
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("您输入的数据有错误！" + ex.ToString());
                Console.ReadLine();
            }
        }
    }
}
